<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function truncate(str = "", len = 0) {
        if (str.length > len) {
          return str.substr(0, len) + "...";
        }
        return str;
      }
      console.log(truncate("What I'd like to te hello abc", 20)); // "What I'd like to te…"
      console.log(truncate("Hi everyone!", 20)); // "Hi everyone!"
    </script>
  </body>
</html>
